<?php

class Text {
	public function filter($text, $bad) {
		return str_replace($bad, '*****', $text);
	}
	
	public function randon($length) {
		$str = 'ABCDEFGHIJLMNOPQRSTUVXZYWKabcdefghijlmnopqrstuvxzywk0123456789';
		$cod = '';
		for ($i = 0; $i < $length; $i++) {
			$rand = rand(0, 63);
			$cod .= substr($str, $rand, 1);
		}
		return $cod;
	}
	
	public function truncate($str, $len = 80, $etc = '') {
		$end = array(' ', '.', ',', ';', ':', '!', '?');
		if (strlen($str) <= $len)
			return $str;
		if (!in_array($str{$len - 1}, $end) && !in_array($str{$len}, $end))
			while (--$len && !in_array($str{$len - 1}, $end));
		return rtrim(substr($str, 0, $len)) . $etc;
	}
}

?>